package com.nicole.reqresp.filters;

import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import java.io.ByteArrayInputStream;

/**
 * @ClassName MyInputStream
 * @Description TODO
 * @Author xiaoying
 * @Date 2022/12/8 20:27
 * @Version V1.0.0
 */
public class MyInputStream extends ServletInputStream {

    private final ByteArrayInputStream inputStream;

    public MyInputStream(byte[] body) {
        this.inputStream = new ByteArrayInputStream(body);
    }

    @Override
    public boolean isFinished() {
        return inputStream.available() == 0;
    }

    @Override
    public boolean isReady() {
        return true;
    }

    @Override
    public void setReadListener(ReadListener readListener) {

    }

    @Override
    public int read() {
        return inputStream.read();
    }
}
